using System;
using System.Collections.Generic;
using System.Linq;
using Millel.Software.Examples.Common.Entities;
using Millel.Software.Examples.Linq.Entities;

namespace Millel.Software.Examples.Linq.Examples
{
    public class SelectMany : AbstractExample
    {
        public override void Run()
        {
            Console.WriteLine("Using SelectMany");
            var starDestroyers = new List<StarDestroyer>
                                     {
                                         new StarDestroyer
                                             {
                                                 TieFighters = new List<TieFigher>
                                                                   {
                                                                       new TieFigher{Pilot = "Darth Vader"},
                                                                       new TieFigher{Pilot = "Biggs Darklighter"}
                                                                   }
                                             },
                                         new StarDestroyer
                                             {
                                                 TieFighters = new List<TieFigher>
                                                                   {
                                                                       new TieFigher{Pilot = "Darth Maul"},
                                                                       new TieFigher{Pilot = "Baron Soontir Fel"}
                                                                   }
                                             }
                                     };
            
            var tieFighters = starDestroyers.SelectMany(n => n.TieFighters);
            foreach (var tieFighter in tieFighters)
            {
                Console.WriteLine(tieFighter.Pilot);
            }

            Console.WriteLine("SelectMany example complete - press any key to continue");
            Console.ReadLine();
        }
    }
}